<template>
  <div>
    <zbTable ref="tableRef" :api-fun="get_list" @action="action" />
    <reject v-if="addShow" v-model:visible="addShow" @done="getNewList" />
    <accpets
      v-if="accpetShow"
      v-model:visible="accpetShow"
      :Code="editData"
      @done="receive"
    />
  </div>
</template>

<script setup>
  import { ref } from 'vue';
  import { message, Modal } from 'ant-design-vue';
  import { useRouter } from 'vue-router';
  import { actionFn } from '@/utils/action.js';
  import { daochuFn } from '@/utils/daochu.js';
  import { PlusOutlined, UploadOutlined } from '@ant-design/icons-vue';
  /* import zbTable from '@/components/zbTable/jewelryManageIndex.vue'; */
  import zbTable from '@/components/zbTable/purchaseManageIndex.vue';
  import {
    get_list,
    receipts_stock_confirm_receive
  } from '@/api/jewelry/receipts_stock';
  import reject from './components/reject.vue';
  import accpets from './components/accpets.vue';
  // 是否显示编辑弹窗
  const showEdit = ref(false);
  const showCheck = ref(false);
  // 获取子组件
  const tableRef = ref(null);
  // 编辑数据
  const editData = ref({});
  // 编辑按钮数据
  const actionData = ref({});
  /* 打开编辑弹窗 */
  const reasonCode = ref({});
  const addShow = ref(false);
  const accpetShow = ref(false);
  const router = useRouter();
  const { push } = useRouter();

  const action = (data) => {
    editData.value.id = data.row_data.id;
    editData.value.code = data.row_data.to_type_code;
    editData.value.djcode = data.row_data.code;
    actionData.value = data.action_data;
    if (data.action_data.type == 'edit') {
      showEdit.value = true;
      actionStatus.value = 'edit';
    } else if (data.action_data.type == 'reject') {
      addShow.value = true;
    } else if (data.action_data.type == 'agree') {
      accpetShow.value = true;
    } else if (data.action_data.type == 'delete') {
      Modal.confirm({
        title: '提示',
        content: '确定删除，删除后不可恢复?',
        maskClosable: true,
        onOk: () => {}
      });
    } else if (data.action_data.type == 'verify') {
      showCheck.value = true;
    } else if (data.action_data.type == 'back_verify') {
      Modal.confirm({
        title: '提示',
        content: '确定反审?',
        maskClosable: true,
        onOk: () => {}
      });
    } else if (data.action_data.type == 'confirm') {
      Modal.confirm({
        title: '提示',
        content: '确定提交审核?',
        maskClosable: true,
        onOk: () => {}
      });
    } else if (data.action_data.type == 'detail') {
      toDetail(data.row_data);
    }
  };
  const toDetail = (record) => {
    console.log('看详情');
    let r = router.currentRoute.value.path.split('/');
    let newUrl = `/${r[1]}/${r[2]}/detail`;
    console.log('newUrl', newUrl);
    push({
      path: newUrl,
      query: { code: record.code }
    });
  };
  const reloadTable = () => {
    // showEdit.value = false;
    addShow.value = false;
    tableRef.value.reload();
  };
  //接收
  const receive = (val) => {
    receipts_stock_confirm_receive({
      code: editData.value.djcode,
      receive_status: 1,
      store_group_code: val
    })
      .then((res) => {
        reloadTable();
        message.success(res.msg);
      })
      .catch((e) => {
        reloadTable();
        message.error(e);
      });
  };
  //拒绝
  const getNewList = (val) => {
    receipts_stock_confirm_receive({
      code: editData.value.djcode,
      receive_status: 2,
      receive_cause: val
    })
      .then((res) => {
        message.success(res.msg);
        reloadTable();
      })
      .catch((e) => {
        message.error(e);
      });
  };
</script>
